package com.itheima.hmshopping.app.controller;

import com.itheima.hmshopping.app.service.PmsProductAttributeCategoryService;
import com.itheima.hmshopping.entity.PmsProductAttributeCategory;
import com.itheima.hmshopping.util.HmPage;
import com.itheima.hmshopping.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/productAttribute/category")
public class PmsProductAttributeCategoryController {

    @Autowired
    private PmsProductAttributeCategoryService pmsProductAttributeCategoryService;

    /**
     * 分页获取所有商品属性分类
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public R getProductAttributeCategoryList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize) {
        HmPage hmPage=pmsProductAttributeCategoryService.getProductAttributeCategoryList(pageNum,pageSize);
        return R.succeed(hmPage,"");
    }

    /**
     * 获取所有商品属性分类及其下属性
     */
    @GetMapping("/list/withAttr")
    public R getAttribute(){
        PmsProductAttributeCategory pmsProductAttributeCategory = pmsProductAttributeCategoryService.getAttribute();
        return R.succeed(pmsProductAttributeCategory,"");
    }
}
